﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cmsservice.Entity
{

    public class VideoItem
    {
        public long coverIndex { get; set; }
        public long lastModified { get; set; }
        public long status { get; set; }
        public string cusCoverURL { get; set; }
        public string tag { get; set; }
        public long categoriesId { get; set; }
        public long videoSize { get; set; }
        public string fileIds { get; set; }
        public long id { get; set; }
        public string title { get; set; }
        public string cutCoverURL { get; set; }
        public bool search { get; set; }
        public long userId { get; set; }
        public long videoLength { get; set; }
        public long uploadTime { get; set; }
        public long uploadFrom { get; set; }
        public string uploadIp { get; set; }
        public long delTag { get; set; }
        public string introduction { get; set; }
        public long ClickCount { get; set; }
        public long Cai { get; set; }
        public long Ding { get; set; }

        private DateTime modifyTime;

        public DateTime ModifyTime
        {
            get
            {
                if (modifyTime != DateTime.MinValue)
                {
                    return modifyTime;
                }
                else
                {
                    if (uploadTime == 0)
                    {
                        uploadTime = lastModified;
                    }
                    modifyTime = DateTime.Parse("1970-1-1").AddMilliseconds(uploadTime).AddHours(8);
                    return modifyTime;
                }
            }
        }

        int titleCount;

        public int TitleCount
        {
            get
            {
                if (titleCount > 0)
                {
                    return titleCount;
                }
                else
                {
                    titleCount = System.Text.Encoding.GetEncoding("gb2312").GetByteCount(title);
                    return titleCount;
                }
            }
        }

        private string smallImgUrl = "";

        public string SmallImgUrl
        {
            get
            {
                if (!string.IsNullOrEmpty(smallImgUrl))
                {
                    return smallImgUrl;
                }
                else
                {
                    if (!string.IsNullOrEmpty(cusCoverURL))
                    {
                        var arr = cusCoverURL.Split(';');
                        if (arr.Length > 1)
                        {
                            smallImgUrl = arr[1];
                        }
                    }
                    return smallImgUrl;
                }
            }
        }

        private string bigImgUrl = "";

        public string BigImgUrl
        {
            get
            {

                if (!string.IsNullOrEmpty(bigImgUrl))
                {
                    return bigImgUrl;
                }
                else
                {
                    if (!string.IsNullOrEmpty(cusCoverURL))
                    {
                        var arr = cusCoverURL.Split(';');
                        if (arr.Length > 0)
                        {
                            bigImgUrl = arr[0];
                        }
                    }
                    return bigImgUrl;
                }
            }
        }

        private string author = "";

        public string Author
        {
            get
            {
                if (!string.IsNullOrEmpty(tag))
                {
                    var tempLst = tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (tempLst.Length > 1)
                    {
                        author = tempLst[1];
                        if (author == "&nbsp;")
                        {
                            author = "";
                        }
                    }
                }
                return author;
            }
        }

        private string lmName = "";

        public string LmName
        {
            get
            {
                if (!string.IsNullOrEmpty(lmName))
                {
                    return lmName;
                }
                else
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var tempLst = tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (tempLst.Length > 0)
                        {
                            lmName = tempLst[0];
                        }
                    }
                    else
                    {
                        return "";
                    }
                }
                return lmName;
            }
        }

        private string search1 = "";
        public string Search1
        {
            get
            {
                if (!string.IsNullOrEmpty(search1))
                {
                    return search1;
                }
                else
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var tempLst = tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (tempLst.Length > 2)
                        {
                            search1 = tempLst[2];
                        }
                    }
                    else
                    {
                        return "";
                    }
                }
                return search1;
            }

        }

        private string search2 = "";

        public string Search2
        {
            get
            {
                if (!string.IsNullOrEmpty(search2))
                {
                    return search2;
                }
                else
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var tempLst = tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (tempLst.Length > 3)
                        {
                            search2 = tempLst[3];
                        }
                    }
                    else
                    {
                        return "";
                    }
                }
                return search2;
            }
        }

        private string search3 = "";

        public string Search3
        {
            get
            {
                if (!string.IsNullOrEmpty(search3))
                {
                    return search3;
                }
                else
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var tempLst = tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (tempLst.Length > 4)
                        {
                            search3 = tempLst[4];
                        }
                    }
                    else
                    {
                        return "";
                    }
                }
                return search3;
            }
        }

        /// <summary>
        /// 时长
        /// </summary>
        public string VideoTimeLen
        {
            get
            {
                var c = TimeSpan.FromSeconds(videoLength);
                int m = (int)c.TotalMinutes;
                int s = c.Seconds;
                return m + ":" + s;
            }
        }

        private string searchTag;

        public string SearchTag
        {
            get
            {
                if (!string.IsNullOrEmpty(searchTag))
                {
                    return searchTag;
                }
                else
                {
                    if (!string.IsNullOrEmpty(tag))
                    {
                        var tempLst = tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                        if (tempLst.Length > 4)
                        {
                            searchTag = tempLst[4];
                        }
                        else
                        {
                            searchTag = "";
                        }
                    }
                    else
                    {
                        return "";
                    }
                }
                return searchTag;
            }
        }
    }
}
